<?php 
 try {
    $dbh = new PDO('mysql:host=127.0.0.1;dbname=1704phpa', 'root','root');
    
    $sql = "select * from  user";

    $data=$dbh->query($sql);

    $res = $data->fetchAll(2);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
 	<title>Document</title>
 </head>
 <body>
 	<center>
 		<table border="1">
 			<tr>
 				<th>电脑图片</th>
 				<th>电脑描述</th>
 				<th>电脑价格</th>
 			</tr>
 			<?php foreach ($res as $key => $value) {?>
 			<tr>
 				<td><?php echo $value['img'];?></td>
 				<td><?php echo $value['desc'];?></td>
 				<td><?php echo $value['shop']?></td>
 			</tr>
 			<?php }?>
 		</table>
 	</center>
 </body>
 </html>